﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BookShop.BLL;
using BookShop.Model;
namespace BookShop2
{
    public partial class EditCategory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int categoryid = Convert.ToInt32(Request.QueryString["cateid"]);
                CategoryInfo cate = CategoriesBLL.GetCategorybyID(categoryid);
                lblCategoryID.Text = cate.CategoryID.ToString();
                txtCategoryName.Text = cate.CategoryName.ToString();
            }
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
           CategoryInfo category = new CategoryInfo();
            category.CategoryID = Convert.ToInt32(Request.QueryString["cateid"]);
            category.CategoryName=txtCategoryName.Text.Trim();
            try
            {
                if (CategoriesBLL.UpdateCategory(category)>0)
                {
                    Response.Write("<script>alert('修改成功！')</script>");
                }
                else
                {
                    Response.Write("<script>alert('修改失败！')</script>");
                }
            }
            catch (Exception)
            {

                throw;
            }
            
        }
    }
}